package prickworlds.graphics;

import static org.lwjgl.opengl.GL11.*;

public class Primitives {
	private static int ellipseVertices = 20;

	/**
	 * draws an ellipse
	 * 
	 * @param x
	 *            the x-coordinate of the center
	 * @param y
	 *            the y-coordinate of the center
	 * @param width
	 *            the width of the ellipse
	 * @param height
	 *            the height of the ellipse
	 */
	public static void drawEllipse(float x, float y, float width, float height) {
		glPushMatrix();
		glTranslatef(x, y, 0.0f);
		glScalef(width, height, 1.0f);
		glBegin(GL_TRIANGLE_FAN);

		for (int i = 0; i < ellipseVertices; i++) {
			glVertex2d(Math.cos(i * 2 * Math.PI / ellipseVertices), Math.sin(i
					* 2 * Math.PI / ellipseVertices));
		}
		glEnd();
		glPopMatrix();
	}

	/**
	 * 
	 * @param x x coordinate of the upper left corner of the rectangle
	 * @param y y coordinate of the upper left corner of the rectangle
	 * @param width
	 * @param height
	 */
	public static void drawRect(float x, float y, float width, float height) {
		glBegin(GL_TRIANGLE_STRIP);
		glVertex2f(x, y);
		glVertex2f(x + width, y);
		glVertex2f(x, y + height);
		glVertex2f(x + width, y + height);
		glEnd();
	}

	/**
	 * To draw an ellipse, a polygon similar to an eclipse is drawn. This
	 * polygon has a standard amount of vertices of 20. This value can however
	 * be changed.
	 * 
	 * @return the amount of vertices used to draw an ellipse by current
	 *         settings
	 */
	public static int getEllipseVertices() {
		return ellipseVertices;
	}

	/**
	 * specifies the number of vertices used to draw an ellipse.
	 * 
	 * Standard value is 20.
	 * 
	 * @param nVertices
	 *            number of vertices
	 */
	public static void setEllipseVertices(int nVertices) {
		Primitives.ellipseVertices = nVertices;
	}
}
